package com.zj.small.util;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpSession;

import java.util.Timer;
import java.util.TimerTask;

// java发送验证码有效期2分钟，过期自动销毁。验证码是否和用户输入的相同。 https://blog.csdn.net/java578764919/article/details/115903797
public class CaptchaTimeUtil {
    //验证码有效时间 https://blog.csdn.net/weixin_44200984/article/details/104056378
    public static void startTimer(String num){
        HttpServletRequest request = null;
        try {
            final HttpSession httpSession=request.getSession();
            httpSession.setAttribute("number",num);
            final Timer timer=new Timer();
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    httpSession.removeAttribute("number");
                    System.out.println("number删除成功");
                    timer.cancel();
                }
            }, 60 * 1000);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static boolean getTimer(String validateCode) {
        HttpServletRequest httpServletRequest = null;
        String num = (String)
                //这里的 NUM_EMAIL 是存在Session里的名字 就好比上面的number
                httpServletRequest.getSession().getAttribute("NUM_EMAIL");
        return validateCode.equals(num);
    }

}
